package com.twu.biblioteca;

import java.util.*;

public class StringJoiner {
    public String join(List<String> strings) {
        if (strings.size() == 0){
            return "";
        }

        List<String> otherStrings = new ArrayList<String>(strings);
        String joinedStrings = otherStrings.remove(0);

        for (String string : otherStrings) {
            joinedStrings += "\n" + string;
        }
        return joinedStrings;
    }


    public String join(Map<String, Book> books) {
        if (books.size() == 0){
            return "";
        }

        Map<String, Book> temp = new TreeMap<String, Book>(books);
        //get first book's index in books
        String firstIdx = null;
        for (String index : temp.keySet()) {
            firstIdx = index;
            break;
        }
        String joinedStrings = firstIdx + "---" + temp.remove(firstIdx).toString();
        for (String index : temp.keySet()) {
            joinedStrings += "\n" + index + "---" + temp.get(index).toString();
        }
        return joinedStrings;
    }
}
